package com.easylinkin.sm.controller;

import com.easylinkin.sm.constant.LogConstant;
import com.easylinkin.sm.entity.Privilege;
import com.easylinkin.sm.service.PrivilegeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.boot.data.CrudControllerSupport;
import site.morn.log.OperateGroup;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;
import site.morn.rest.RestModel;
import site.morn.validate.group.Search;

/**
 * 权限管理
 *
 * @author wujie
 * @since 0.1.1,  2019/08/28
 */
@Api(tags = "权限管理")
@OperateGroup(value = "privilege", args = LogConstant.Module.PRIVILEGE)
@RestController
@RequestMapping("/privilege")
public class PrivilegeController extends CrudControllerSupport<Privilege, Long, PrivilegeService> {

  @ApiOperation("查询所有")
  @PostMapping({"searchAll"})
  public RestMessage searchAll(
      @Validated({Search.class}) @RequestBody RestModel<Privilege> restModel) {
    List<Privilege> privileges = this.service().searchAll(restModel);
    return RestBuilders.successMessage(privileges);
  }

  @ApiOperation(value = "权限树查询,全量查询")
  @GetMapping("searchTree/{disabled}")
  public RestMessage searchPrivilegeTree(@PathVariable Integer disabled){
    return RestBuilders.successMessage(service().searchPrivilegeTree(disabled));
  }
}
